package com.vy.stl.fore;

import com.vy.stl.constants.Constants;
import com.vy.stl.entity.Member;
import com.vy.stl.service.MemberService;
import com.vy.stl.util.JWTUtil;
import com.vy.stl.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @create: 2025/09/10 13:44
 * @description:
 */
@RestController("foreMemberController")
@RequestMapping( value = "/fore")
public class MemberController {

    @Autowired
    private MemberService memberService;

    @RequestMapping("/member/login")
    public Result login(@RequestBody Member member) {
        try {
            Member loginMember = memberService.login(member);
            String token = JWTUtil.createJWT(loginMember.getPhone());
            return Result.success(Constants.STATUS_200,token,loginMember);
        } catch (Exception e) {
            return Result.error(Constants.MEMBER_LOGIN_ERROR,e.getMessage());
        }
    }
}